using System.Collections;

using System.Diagnostics;

using CStock;
using System;


using NUnit.Framework;

using CIndicators;
using TestCases.StockData;

namespace TestCases.Indicators
{
	
	[TestFixture] 
	public class IndicatorTest
	{
		IIndicator indicator;
		IDataClass dataClass;
		//IProgramContext programContext;
		[SetUp] 
		public void Init() 
		{
			
			//new share, with some sample data
			DataClassTest dct = new DataClassTest();

            dataClass = dct.DataClassFactory.StockObjectBase as IDataClass;
	
		}
		[Test] 
		public void SaveDummy() 
		{
			//new indicator
			indicator = new CIndicators.Indicator();
			indicator.NameBase = "CLOSE";
			indicator.Parent = dataClass;
			
			
			indicator.IndicatorType = CUtil.IndicatorType.OHLCV;
			indicator.IndicatorSubTypes = CUtil.IndicatorSubTypes.OHLC;


			indicator.Serialize();

		}
		[Test] 
		public void EvaluateMA5() 
		{
            indicator = new CIndicators.MovingAverageExponential();
			indicator.Interval = 5;
			indicator.Parent = dataClass;
            indicator = IndEvaluator.Indicator_XMLOrEvaluate(indicator); //saves the indicator !
            
		
		}
		[Test] 
		public void GetMA5() 
		{
            indicator = new CIndicators.MovingAverageExponential();
			indicator.Interval = 5;
			indicator.Parent = dataClass;
			
			object o = indicator.DeSerialize();
			if(o != null)
			{
				indicator = o as Indicator;

				Debug.WriteLine(indicator.Values.Count.ToString());

				
			

			}
		}
        public void CreateMA4()
        {
            IIndicator ind = this.dataClass.CreateIndicator("MovingAverageExponential_2");
            //ind.Serialize();


        }

		[Test] 
		public void EvaluateAllIndicators_BuiltIn()
		{
			//public static ArrayList GetIndicatorsComposed()

			ArrayList arr = IndEvaluator.GetIndicatorsBuiltIn();
			for(int i = 0; i < arr.Count; i++)
			{
				indicator = arr[i] as IIndicator;
				
				indicator.Interval = 5;
				indicator.Parent = dataClass;

                indicator = IndEvaluator.Indicator_XMLOrEvaluate(indicator);
            
				indicator.Serialize();

				//indicatorsAvailable.Add(arr[i]);
			}
		}
		[Test] 
		public void GetAllIndicators_BuiltIn()
		{
			//public static ArrayList GetIndicatorsComposed()

			ArrayList arr = IndEvaluator.GetIndicatorsBuiltIn();
			for(int i = 0; i < arr.Count; i++)
			{
				indicator = arr[i] as IIndicator;
				indicator.Interval = 5;
				indicator.Parent = dataClass;
			
				object o = indicator.DeSerialize();
				if(o == null)
				{
					Debug.Assert(false,"Could not get indicator " + indicator.Name);
				}
			
				//indicatorsAvailable.Add(arr[i]);
			}
		}

	
	}
}